package top.jnaw.test.service;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;
import top.jnaw.test.model.Users;

/**
 * Permissions 管理
 * 描述：
 */
public class UserService {

	//private static final Log log = Log.getLog(PermissionsService.class);
  public static final Users dao = new Users().dao();


  /**
   * 根据用户名获取用户dao
   *
   * @param username 用户名
   */
  public static Record getUserInfo2(String username) {
    Record users = Db.findFirst("SELECT "
        + "  u.id, "
        + "  u.username, "
        + "  u.name "
        + " FROM users u "
        + " WHERE u.username = ? ", username);
    return users;
  }

  /**
   * 根据用户名获取用户dao
   *
   * @param id 用户名
   */
  public static Record getUserInfo(int id) {
    Record users = Db.findFirst("SELECT "
        + "  u.id, "
        + "  u.username, "
        + "  u.name "
        + " FROM users u  "
        + " WHERE u.id = ? ", id);
    return users;
  }
  public static List<Users> getUserList() {
    String sql = "select * from users";
    List<Users> usersList = dao.find(sql);
    return usersList;
  }

  //查询用户的所有角色
  public static List<Record> getList(String name) {
    String sql = "SELECT "
        + "  ur.id,"
        + "  ur.role_name AS role "
        + "   FROM user_roles ur  "
        + " WHERE ur.username = ? ";
    List<Record> list = Db.find(sql, name);
    return list;
  }

}